import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:flutter/material.dart';
import 'package:city_pickers/city_pickers.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBCommonToast/YBCommonToastPage.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBHomePage/YBHomePageProvider/YBCitySelectEventBus.dart';

class YBCitySelectPage {

  void clickTaggle(BuildContext context) async {
    Result temResult = await CityPickers.showCitiesSelector(
      context: context,
      title: "城市选择",
      hotCities: [
        HotCity(name: '北京', id: 0),
        HotCity(name: '上海', id: 1),
        HotCity(name: '广州', id: 2),
        HotCity(name: '深圳', id: 3),
        HotCity(name: '杭州', id: 4),
      ],
      cityItemStyle: BaseStyle(
        color: YBColor.color1B1C1F,
        fontSize: YBTextStyle.adapterSize14,
        activeColor: YBColor.commonThemeColor,
      ),
    );

    if (temResult == null) {
       return;
    }
    print('---${temResult.cityName}--');
    eventBus.fire(YBCitySelectEventBus(temResult.cityName));
  }

  void requestLocation() async{
    if (await requestPermission()){
      final location = await AmapLocation.instance.fetchLocation();
       print('地理位置信息--------${location.city}');
       eventBus.fire(YBCitySelectEventBus(location.city));
    }
  }

  Future<bool> requestPermission() async {
    final permission = await Permission.locationWhenInUse.request();
    if (permission.isGranted) {
       return true;
    }else{
      YBToast.showToastInfo("请开启定位权限");
      return false;
    }
  }
}



